﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeBuilder2.Model.Enumeration;
using System.Xml;

namespace CodeBuilder2.BLL.Convertor
{
    class DataTypeConvertor
    {
        /// <summary>
        /// 根据数据库中数据类型的名称转换成 .Net 类型
        /// </summary>
        /// <param name="dataType">数据库类型名称</param>
        /// <returns>转换后的 .Net 类型</returns>
        public static Type GetDataTypeName(string dataType)
        {
            DataTypeEnum dte = (DataTypeEnum)Enum.Parse(typeof(DataTypeEnum), dataType, true);
            Type t=null;
            switch (dte)
            {
                case DataTypeEnum.BigInt:
                case DataTypeEnum.Int:
                case DataTypeEnum.TinyInt:
                case DataTypeEnum.SmallInt:
                    t = typeof(int);
                    break;
                case DataTypeEnum.Bit:
                    t = typeof(bool);
                    break;
                case DataTypeEnum.Decimal:
                case DataTypeEnum.Money:
                case DataTypeEnum.Numeric:
                case DataTypeEnum.SmallMoney:
                    t = typeof(decimal);
                    break;
                case DataTypeEnum.Float:
                    t = typeof(float);
                    break;
                case DataTypeEnum.Real:
                    t = typeof(double);
                    break;
                case DataTypeEnum.Date:
                    
                case DataTypeEnum.DateTime2:
                case DataTypeEnum.DateTime:
                case DataTypeEnum.DateTimeOffset:
                case DataTypeEnum.SmallDateTime:
                case DataTypeEnum.Time:
                    t = typeof(DateTime);
                    break;
                case DataTypeEnum.Char:
                case DataTypeEnum.Text:
                case DataTypeEnum.VarChar:
                case DataTypeEnum.NChar:
                case DataTypeEnum.NText:
                case DataTypeEnum.NVarChar:
                    t = typeof(string);
                    break;
                case DataTypeEnum.Binary:
                case DataTypeEnum.Image:
                case DataTypeEnum.VarBinary:
                    t = typeof(byte);
                    break;
                case DataTypeEnum.Cursor:
                    break;
                case DataTypeEnum.Hierarchyid:
                    break;
                case DataTypeEnum.Sql_Variant:
                    break;
                case DataTypeEnum.Table:
                    break;
                case DataTypeEnum.TimeStamp:
                    t = typeof(TimeSpan);
                    break;
                case DataTypeEnum.UniqueIdentifier:
                    break;
                case DataTypeEnum.XML:
                    t = typeof(XmlDocument);
                    break;
                default:
                    break;
            }
            return t;
        }
    }
}
